export default class Utils {
    /** 获取两点距离 */
    static getDistance(pos1: { x: number, y: number }, pos2: { x: number, y: number }) {
        return Math.sqrt(Math.pow((pos2.x - pos1.x), 2) + Math.pow((pos2.y - pos1.y), 2));
    }

    static randomString(len: number){
        let $chars = `ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678`;
        let maxPos = $chars.length;
        let str = ``;
        for(let i = 0; i < len; ++i){
            str += $chars.charAt(Math.floor(Math.random() * maxPos));
        }
        return str;
    }

    static randomIntStr(len){
        let $chars = `0123456789`;
        let maxPos = $chars.length;
        let str = ``;
        for(let i = 0; i < len; ++i){
            str += $chars.charAt(Math.floor(Math.random() * maxPos));
        }
        return str;
    }

    static randomInt(begin: number, end: number){
        let num = begin + Math.random() * (end - begin + 1);
        num = Math.floor(num);
        if(num > end){
            num = end;
        }
        return num;
    }
}
